package com.ruoyi.buildingacidsys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.buildingacidsys.domain.BuildingNucleicAcid;
import com.ruoyi.buildingacidsys.service.IBuildingNucleicAcidService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 楼栋核酸任务Controller
 * 
 * @author ruoyi
 * @date 2024-07-28
 */
@RestController
@RequestMapping("/buildingacidsys/buildingacid")
public class BuildingNucleicAcidController extends BaseController
{
    @Autowired
    private IBuildingNucleicAcidService buildingNucleicAcidService;

    /**
     * 查询楼栋核酸任务列表
     */
    @PreAuthorize("@ss.hasPermi('buildingacidsys:buildingacid:list')")
    @GetMapping("/list")
    public TableDataInfo list(BuildingNucleicAcid buildingNucleicAcid)
    {
        startPage();
        List<BuildingNucleicAcid> list = buildingNucleicAcidService.selectBuildingNucleicAcidList(buildingNucleicAcid);
        return getDataTable(list);
    }
    @GetMapping("/selectAll")
    public TableDataInfo selectAllbuildingNucleicAcid()
    {
        List<BuildingNucleicAcid> list = buildingNucleicAcidService.selectAllBuildingNucleicAcid();
        return getDataTable(list);
    }

    /**
     * 导出楼栋核酸任务列表
     */
    @PreAuthorize("@ss.hasPermi('buildingacidsys:buildingacid:export')")
    @Log(title = "楼栋核酸任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuildingNucleicAcid buildingNucleicAcid)
    {
        List<BuildingNucleicAcid> list = buildingNucleicAcidService.selectBuildingNucleicAcidList(buildingNucleicAcid);
        ExcelUtil<BuildingNucleicAcid> util = new ExcelUtil<BuildingNucleicAcid>(BuildingNucleicAcid.class);
        util.exportExcel(response, list, "楼栋核酸任务数据");
    }

    /**
     * 获取楼栋核酸任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('buildingacidsys:buildingacid:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(buildingNucleicAcidService.selectBuildingNucleicAcidById(id));
    }

    /**
     * 新增楼栋核酸任务
     */
    @PreAuthorize("@ss.hasPermi('buildingacidsys:buildingacid:add')")
    @Log(title = "楼栋核酸任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuildingNucleicAcid buildingNucleicAcid)
    {
        //如果是发布任务正在进行中1 一开始
        //设置默认状态为未开始：0
        buildingNucleicAcid.setStatus(1L);
        return toAjax(buildingNucleicAcidService.insertBuildingNucleicAcid(buildingNucleicAcid));
    }

    /**
     * 修改楼栋核酸任务
     */
    @PreAuthorize("@ss.hasPermi('buildingacidsys:buildingacid:edit')")
    @Log(title = "楼栋核酸任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuildingNucleicAcid buildingNucleicAcid)
    {
        return toAjax(buildingNucleicAcidService.updateBuildingNucleicAcid(buildingNucleicAcid));
    }

    /**
     * 删除楼栋核酸任务
     */
    @PreAuthorize("@ss.hasPermi('buildingacidsys:buildingacid:remove')")
    @Log(title = "楼栋核酸任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(buildingNucleicAcidService.deleteBuildingNucleicAcidByIds(ids));
    }
}
